package deneme;

import java.awt.EventQueue;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JTextField;

public class main {

	private JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					main window = new main();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public main() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		final velocity vel = new velocity();
		frame = new JFrame();
		frame.setBounds(100, 100, 800, 600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		final JLabel ball = new JLabel("New label");
		ball.setIcon(new ImageIcon(main.class.getResource("/javax/swing/plaf/basic/icons/JavaCup16.png")));
		ball.setBounds(130, 156, 18, 27);
		frame.getContentPane().add(ball);
		
		Timer timer = new Timer();
		Timer timer2 = new Timer();
		Timer timer3 = new Timer();
		
		timer2.scheduleAtFixedRate(new TimerTask() {

			  @Override
			  public void run() {
				  ball.setLocation(ball.getX(), ball.getY()+vel.getVelY());

			  }
			}, 100, 50);
		
		timer.scheduleAtFixedRate(new TimerTask() {

			  @Override
			  public void run() {
					  vel.setVelY(vel.getVelY()+1);
			  }
			}, 100, 150);
		timer3.scheduleAtFixedRate(new TimerTask() {

			  @Override
			  public void run() {
				  if((ball.getY()>400)){
					  
					  vel.setVelY(6*(-1)*vel.getVelY()/10);
					  ball.setLocation(ball.getX(),399);
				  } 
				  /*}else if((ball.getY()>400)&&(vel.getVelY()>-5)){
					  
					  vel.setVelY(0);
					  ball.setLocation(ball.getX(),399);
				  }*/
			  }
			}, 100, 1);
	}
}
